package com.fengdi.everyday.easy;


/**
 * @Description 1437 是否所有1都至少相隔K个元素
 * @Date 09:09
 */
public class KLengthApart {
    public boolean kLengthApart(int[] nums, int k) {
        int preIndex = -1;
        int len = nums.length;

        for(int i = 0; i < len; i++) {
            if(nums[i] == 1) {
                if(preIndex != -1 && i - preIndex < k + 1) {
                    return false;
                }
                preIndex = i;
            }
        }
        return true;
    }
}
